package com.tr.rentcar.controller.houtai.usermanage;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.JOptionPane;

import com.tr.rentcar.model.bean.User;
import com.tr.rentcar.model.bean.UserRecord;
import com.tr.rentcar.model.dao.UserDao;
import com.tr.rentcar.model.dao.UserRecordDao;
@WebServlet("/koufei")
public class KoufeiController extends HttpServlet {
	User User=new User();
	UserDao UserDao=new UserDao();
	UserRecordDao UserRecordDao=new UserRecordDao();
	UserRecord UserRecord=new UserRecord();
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		try {
		String reducemoney=req.getParameter("reducemoney");
		String tel3=req.getParameter("tel3");
		if(UserDao.findByTel(tel3)==null){
			PrintWriter pw=resp.getWriter();
			pw.write("<script language='javascript'>alert('此用户电话不存在')</script>");
		}
		else{
			User user=UserDao.findByTel(tel3);
		UserRecord.setuId(Integer.parseInt(user.getUid()+""));
		UserRecord.setUrWay("扣费");
		UserRecord.setUrMoney(Double.valueOf("-"+reducemoney));
		UserRecord.setUrdoWay("管理员");
		UserRecord.setUrName("sb");
		if(UserRecordDao.save(UserRecord))
		{user.setUmoney(user.getUmoney()+UserRecord.getUrMoney());
		UserDao.xgmoney(user.getUmoney(),user.getUid());
		};
		resp.sendRedirect(req.getContextPath()+"/houtaiuser");
		}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	
		doGet(req, resp);
	}
	
	
}
